package com.example.qcrmdemo.service.impl;

import com.example.qcrmdemo.dao.RoleMapper;
import com.example.qcrmdemo.entity.Role;
import com.example.qcrmdemo.service.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired(required = true)
    private RoleMapper roleMapper;
    @Override
    public Role findByNamePass(String username, String password) {
        return roleMapper.selectByNamePass( username,password);
    }

    @Override
    public boolean append(Role role) {
        return roleMapper.insert(role)>0;
    }

    @Override
    public PageInfo<Role> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<Role> roles=roleMapper.selectByKeyword(keyword);
        PageInfo<Role> pageInfo=new PageInfo<>(roles);
        return pageInfo;
    }

    @Override
    public Role findById(int id) {
        return roleMapper.selectById(id);
    }

    @Override
    public boolean modify(Role role) {
       return roleMapper.updateById(role)>0;
    }

    @Override
    public boolean remove(int id) {
        return roleMapper.deleteById(id)>0;
    }
}
